//
//  MFWDownloadManager.h
//  download
//
//  Created by 陈曦 on 13-4-24.
//  Copyright (c) 2013年 陈曦. All rights reserved.
//

#import <UIKit/UIKit.h>
#import "MFWDownloadItem.h"

// 通知所带字典中数据的key
// 所有通知均会回传index 类型为NSNumber.NSUInteger
extern NSString* MFW_DOWNLOAD_NOTIFY_INDEX_KEY;

// 一共两种通知
// 状态变化通知 下载完成和错误也在这里通知
extern NSString* MFW_DOWNLOAD_STATE_CHANGE_NOTIFY;

// 百分比有变化通知
extern NSString* MFW_DOWNLOAD_PERCENT_CHANGE_NOTIFY;

typedef struct {
    unsigned long long totalLength;
    unsigned long long downloadLength;
    CGFloat percent;
} MFWDownloadProgress;

@interface MFWDownloadManager : NSObject

@property (nonatomic, assign) NSUInteger MaxConcurrentDownloadCount;
@property (nonatomic, readonly, copy) NSString *catalogName;

+ (id)defaultManager;
+ (id)managerNamedCatalog:(NSString*)aCatalogName;

// 初始化相关
// 如果要使用自己的主键请传入ID 返回索引
- (NSUInteger)startDownloadFile:(NSString *)aUrl
               withLocalPath:(NSString *)aPath;

- (NSUInteger)startDownloadFile:(NSString *)aUrl
                  withLocalPath:(NSString *)aPath
                          andID:(NSString*)aID;

// 获取所有信息
// 返回字符串类型的数组  所有ID
- (NSArray*)getAllUUID;

// same to [self getAllUUID].count
- (NSUInteger)getCount;

- (NSString*)getUUIDByIndex:(NSUInteger)aIndex;
- (NSUInteger)getIndexByUUID:(NSString*)aUUID;


- (NSUInteger)getIndexByUrl:(NSString*)aUrl;// 如果大于等于[self getCount]则不存在此url
- (NSString*)getUUIDByUrl:(NSString*)aUrl;

// 根据索引获取信息
- (MFWDownloadState)getStateByIndex:(NSUInteger)aIndex;
- (NSString*)getUrlByIndex:(NSUInteger)aIndex;
- (NSString*)getLocalPathByIndex:(NSUInteger)aIndex;
- (MFWDownloadProgress)getProgressByIndex:(NSUInteger)aIndex;

// 下载操作
- (void)stopByIndex:(NSUInteger)aIndex;
- (void)stopAll;

- (void)startByIndex:(NSUInteger)aIndex;
- (void)startAll;

- (void)deleteByIndex:(NSUInteger)aIndex ifFinishedDeleteFile:(BOOL)aDelete;

// 挂起所有操作 用于网络状态转换  挂起后可以单独指定任务开启
- (void)pause;
// 恢复所有操作
- (void)resume;

@end
